/* 
 * Copyright 2011 kOSMik.
 * This file is part of kOSMik.
 * 
 * kOSMik is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * kOSMik is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with kOSMik.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * kOSMik:
 * Open Street Map - Editor.
 * http://code.google.com/p/swp-dv-ws2010-osm-2/
 */

package de.fuberlin.kosmik.data.osmt;

import android.content.ContentValues;

/**
 * Package intern interface. Provides basic functionality of the database.
 * 
 * @author Johannes
 * 
 */
interface OsmtDatabase {

	/**
	 * Inserts a record into the database.
	 * 
	 * @param osmtTable the target table into which the row should be written.
	 * @param values are forming the record that should be written.
	 * @return true, if the record was written, and false, if the was not
	 *         written. A cause is for e.g. that a SQLiteContraintsException
	 *         occur.
	 */
	boolean insertRecord(OsmtTable osmtTable, ContentValues values);

	/**
	 * Handles a query. Forward the query encapsulated in the OsmtQuery-object
	 * and return the gained cursor to the callback-method.
	 * 
	 * @param query The encapsulated query that forwarded to the database
	 * @param onObtainCursorListener that implements the onObtainCursor-method
	 *            to process the query results
	 * @return the result that returned by onObtainCursor
	 */
	boolean query(OsmtQuery query, OnObtainCursorListener onObtainCursorListener);

	/**
	 * Handles a raw query. Return the gained cursor to the callback-method.
	 * 
	 * @param query The raw query string.
	 * @param onObtainCursorListener that implements the onObtainCursor-method
	 *            to process the query results
	 * @return the result that returned by onObtainCursor
	 */
	boolean query(String query, OnObtainCursorListener onObtainCursorListener);

	/**
	 * Updates an record that already exists.
	 * 
	 * @param osmtTable identifies the table on which the update is performed.
	 * @param values which replaces the old ones
	 * @param whereClause specifies the condition under which the update is to
	 *            take place.
	 * @param whereArgs are arguments that inserts in the whereClause.
	 *            whereClause and whereArgs are optional. Passing null will
	 *            update all rows.
	 * @return true, if update happen, otherwise false
	 */
	boolean update(OsmtTable osmtTable, ContentValues values, String whereClause,
			String[] whereArgs);

	/**
	 * Deletes an record or more that fit the passed delete conditions.
	 * 
	 * @param osmtTable identifies the table on which the delete action should
	 *            be.
	 * @param whereClause specifies the condition which limit the delete action
	 *            to a subset of items.
	 * @param whereArgs are arguments that inserts in the whereClause.
	 *            whereClause and whereArgs are optional. Passing null will
	 *            delete all rows.
	 * @return true, if deletion succeed, otherwise false
	 */
	boolean delete(OsmtTable osmtTable, String whereClause, String[] whereArgs);

}
